<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
       <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>${title }</title>
    <link rel="stylesheet" href="${basePath}/static/bootstrap/css/bootstrap.css"/>
    <link href="${basePath}/static/css/basic.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/login.css" rel="stylesheet" type="text/css">
    <link href="${basePath}/static/css/list.css" rel="stylesheet" type="text/css">
    <script  type="text/javascript" src="${basePath}/static/js/jquery.min.js"></script>
	<script  type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript" src="${basePath}/static/page/jqPaginator/jqPaginator.js"></script>
    <script  type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
    <link href="${basePath}/static/layer/layer_defined.css" rel="stylesheet" type="text/css">
    <style>
     .td_input_box{
        width: 95%;
	    height: 28px;
	    text-align: left;
	    text-indent: 5px;
	    line-height: 20px;
	    border-bottom: #fec99c solid 1px;
	    border-top: #FFF solid 1px;
	    border-left: #FFF solid 1px;
	    border-right: #FFF solid 1px;
     }
     .btn{
      background: #039b8e;
      color:#fff;
     }
     .td_relative{
      position:relative;
      }
     .checkList{
      display:none;
      position:absolute;
      top:35px;
      left:10px;
      border:1px solid #ccc;
      width:95%;
      height:150px;
      overflow-y:scroll;
      background:#fff;
      z-index:1000;
     }
     .checkList ul{
      width:100%;
      height:100%;
      margin-top:20px;
     }
     .checkList li{
      width:100%;
      height:auto;
      line-height:30px;
      padding:0 5px;
      text-align:left;
     }
     .checkList li:hover{
      background-color:#EAF4F6;
     }
     .int {
	    background: #07a396;
	    color: #FFF;
	    border-radius: 4px;
	    cursor: pointer;
	    padding: 4px;
	}
	.close{
	   position:absolute;
	   top:5px;
	   right:5px;
	   width:20px;
	   height:20px;
	   text-align:center;
	   line-height:20px;
	   cursor:pointer;
	}
    </style>
</head>
<body>
<!--头部-->
	<%@include file="/WEB-INF/templates/common/header.jsp"%>
	<!------导航条-->
	<%@include file="/WEB-INF/templates/common/navigation.jsp"%>

<!--内容部分-->
<div class="list_main lay_out" class="clearfix">
    <div class="list_DH">
        <%@include file="/WEB-INF/templates/common/indexPageAudit.jsp"%>
    </div>
    <div class="list_NR">
        <div class="loc">
            <h3 style="margin:0">添加数据人工质控记录</h3>
        </div>
        <div class="list_con_table" style="overflow:visible">
        	<input type="hidden" value="${hospitalNote.firstGuid}" id="firstGuid"/>
        	 <div class="search_table">
                <ul class="clearfix" style="margin-bottom:0;border-bottom:#e3e5e4 1px solid">
				    <li class="Label_1">病案号：&nbsp;</li>
				    <li class="Label_2">${hospitalNote.onlyId }</li>
				    <li class="Label_1">识别码：&nbsp;</li>
				    <li class="Label_2">${hospitalNote.mrId}</li>
				    <li class="Label_1">姓名：&nbsp;</li>
				    <li class="Label_2">${hospitalNote.name}</li>
				    <li class="Label_1">身份证号：&nbsp;</li>
				    <li class="Label_2">${hospitalNote.idNumber}</li>
				    <li class="Label_1">出院日期：&nbsp;</li>
				    <li class="Label_2">
				    <fmt:formatDate value="${hospitalNote.outHospitalDate}" pattern="yyyy-MM-dd" /> 
                    	
                    </li>
				    <li class="Label_1">出院科室：&nbsp;</li>
				    <li class="Label_2">${hospitalNote.outHospitalOfficeName}</li>
				    <!--<li class="Label_5">
				     <a onclick="save()">添加缺陷</a><a onclick="add()">新增审核</a>
				    </li>-->
				  </ul>
				  <form id="tableForm" style="width: 100%; height: auto;">
				  	  <table class="Search_tableList">
				  	    <thead>
				  	       <tr>
                                <td class="tdLabel_4" width="50%">质控内容</td>
                                <td class="tdLabel_4" width="30%">质控时间</td>
                                <td class="tdLabel_4" width="20%">操作</td>
                            </tr>
				  	    </thead>
				  	    <tbody id="tbody">
                           <tr>
                                <td class="tdLabel_5 td_relative">
                                    <input type="text" name='remark' class="td_input_box check_input" oninput="check(this)">
                                    <div class="checkList">
                                       <div class="close" onclick="hide(this)">X</div>
                                       <ul>
                                         <!-- <li onclick="check_click(event)">11</li> -->
                                       </ul>
                                	</div>
                                   <input type="hidden" name="auditingStandardId" >
                                 
                                </td>
                                <td class="tdLabel_5">
                                    <input type="text" name="createTime" class="td_input_box" onFocus="WdatePicker()">
                                </td>
                                <td class="tdLabel_5"><a class="int" onclick="save(this)">保存</a>
                                </td>
                             </tr>
                        </tbody>
                    </table>
   			
				  </form>
			</div>   
        </div> 	
    </div>
</div>
<input type="hidden" id="firstGuid" value="${firstLevelMedical.firstGuid}">
<!------页脚部分--------->
<%@include file="/WEB-INF/templates/common/footer.jsp"%>

<!--JS部分-->

<script>
//判断浏览器是ie9以下版本，oninput事件用onpropertychange代替
if(navigator.appName == "Microsoft Internet Explorer"&&parseInt(navigator.appVersion.split(";")[1].replace(/[ ]/g, "").replace("MSIE",""))<9){
    $(".check_input").removeAttr("oninput").attr("onpropertychange","check(this)")}                                     
</script>
<script type="text/javascript">
    //拿到guid值
    var guid=$("#firstGuid").val();
    //审核新增事件
	function add(){
	  	var cloneTr=$("#tbody tr:eq(1)").clone("true");
	  	$(cloneTr).find("a").attr("hidden",false);
	  	$(cloneTr).find("input").val("");
	  	$("#tbody").append(cloneTr)
	}
    //删除事件
	function del(ev){
		var target=$(ev);
		target.closest('tr').remove();
	}
   
    //input中change事件
    function check(ev){
    	var target=$(ev);
    	var name=target.val();
    	//alert(name)
    	if(!name){
    		target.next(".checkList").hide();
    		return;
    	}
    	$.ajax({
    	    type:'post',
    	    async:false,
    		url:"${basePath}/audit/getAuditStandard",
    		data:{name:name},
    		success:function(data){
    		
    			
    			if(data.success){
    				var datalist=data.data;
    				var html="";
    				if(datalist.length){
    				  	for(var i=0;i<datalist.length;i++){
    				  		html+='<li data-id='+datalist[i].code+' data-code='+datalist[i].code+' onclick="check_click(this)">'+datalist[i].name+'</li>'
    				  	}
    				  	target.next('.checkList').find("ul").html("").html(html);
    				  	target.next('.checkList').show();
    				}
    			}
    		}
    	})
    }
    
    //查询审核内容 li点击事件
    function check_click(ev){
    	var target=$(ev);
    	var val=target.text();
    	var id=target.attr("data-id");
    	var code=target.attr("data-code");
    	target.closest(".checkList").prev("input").val("").val(val);
    	target.closest(".checkList").next("input").val("").val(id);
    	target.closest(".checkList").next("input").val("").val(code);
        target.closest(".checkList").hide();
    }
    //关闭查询审核内容弹框
    function hide(obj){
    	$(obj).closest(".checkList").hide();
    }
    //保存事件
    function save(ev){
    	var target=$(ev);
    	var trList=target.closest("tr");
    	var remark=$(trList).find("input[name='remark']").val();
		var createTime=$(trList).find("input[name='createTime']").val();
		if(remark==""||createTime==""){
			 layer.alert("审核内容或者审核时间不能为空！",{icon:7, title:"提示信息"}); 
			 return;
		}
		var auditingStandardId = $(trList).find("input[name='auditingStandardId']").val();
		var auditErrorList = [];
    	var auditQuery = {};
    	auditErrorList.push({"medicalErrorId":auditingStandardId, "createTime":createTime});
    	auditQuery.auditErrorList = auditErrorList;
     	auditQuery.firstGuid = $("#firstGuid").val();
     	console.log(auditQuery)
     	$.ajax({
    		type:'post',
    		dataType: 'json',
    		data:JSON.stringify(auditQuery),
    		contentType : 'application/json;charset=utf-8', //设置请求头信息 
    		url:"${basePath}/audit/addAuditRecordDetail",
    		success:function(data){
    			console.log(data)
    			if(data.success){
    				var saveHtml='<tr><td class="tdLabel_5">'+remark+'</td>'+
                                 '<td class="tdLabel_5">'+createTime+'</td>'+
                                 '<td class="tdLabel_5"><a class="int" data-id='+auditingStandardId+' onclick="del(this)">删除</a></td></tr>';
                    $("#tbody tr").last().before(saveHtml); 
                    $(trList).find("input[name='remark']").val("");
            		$(trList).find("input[name='createTime']").val("");
            		$(trList).find("input[name='auditingStandardId']").val("");
            		
    			}else{
    				layer.alert('添加审核记录失败！', {icon: 5});
    			}
    		}
    	});
    }
    /*function save(){
    	var trList=$("#tbody tr");
    	var auditErrorList = [];
    	var auditQuery = {};
     	for(var i=1;i<trList.length;i++){
    		var remark=$(trList[i]).find("input[name='remark']").val();
    		var createTime=$(trList[i]).find("input[name='createTime']").val();
    		if(remark==""||createTime==""){
    			 layer.alert("审核内容或者时间不能为空！",{icon:2, title:"提示信息"}); 
    			 return;
    		}
    		var remark = $(trList[i]).find("input[name='remark']").val();
    		var auditingStandardId = $(trList[i]).find("input[name='auditingStandardId']").val();
    		var createTime = $(trList[i]).find("input[name='createTime']").val();
    		auditErrorList.push({"medicalErrorId":auditingStandardId, "createTime":createTime});
     	} 
     	auditQuery.auditErrorList = auditErrorList;
     	auditQuery.firstGuid = $("#firstGuid").val();
    	
    	$.ajax({
    		type:'post',
    		dataType: 'json',
    		data:JSON.stringify(auditQuery),
    		contentType : 'application/json;charset=utf-8', //设置请求头信息 
    		url:"${basePath}/audit/addAuditRecordDetail",
    		success:function(data){
    			if(data.success){
    				var firstGuid=$("#firstGuid").val();
    				layer.msg('保存缺陷成功！', {icon: 1});
    				location = "${basePath}/audit/medFileCheck_detail2?firstGuid="+firstGuid;
    			}else{
    				layer.msg('保存缺陷失败！', {icon: 5});
    			}
    		}
    	});
    }*/
    
</script>

</body>
</html>